<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="125px">
      <el-form-item label="订单编号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入订单标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="课程" prop="kcName">
        <el-input
          v-model="queryParams.kcName"
          placeholder="请输入课程"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:order:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:order:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
           <el-button
             type="warning"
             plain
             icon="el-icon-download"
             size="mini"
             @click="handleExport"
             v-hasPermi="['business:order:export']"
           >导出
           </el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
<!--      <el-table-column label="订单标题" align="center" prop="title" />-->
      <el-table-column label="订单编号" align="center" prop="orderNo" />
      <el-table-column label="订单时间" align="center" prop="createTime" />
      <el-table-column label="用户" align="center" prop="nickName" />
      <el-table-column label="学员姓名" align="center" prop="name" />
      <el-table-column label="联系方式" align="center" prop="linkPhone" />

      <el-table-column label="课程" align="center" prop="kcName" />
<!--      <el-table-column label="期望上课时间" align="center" prop="qwskDate" />-->

<!--      <el-table-column label="时间" align="center" prop="createTime" width="160"/>-->

      <el-table-column label="实付金额" align="center" prop="totalFee" />
<!--      <el-table-column label="优惠金额" align="center" prop="yhJe" />-->
<!--      <el-table-column label="原来金额" align="center" prop="ylJe" />-->
      <el-table-column label="订单状态" align="center" prop="orderStatus" />
      <el-table-column label="推荐人" align="center" prop="tjPerson" />
      <el-table-column label="推荐人联系方式" align="center" prop="tjPersonPhone" />
      <el-table-column label="教练" align="center" prop="coachInfoName" />
      <el-table-column label="交付中心" align="center" prop="paCenterName" />

<!--      <el-table-column label="期望上课时间" align="center" prop="qwskDate" />-->

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdatetk(scope.row)"
          >退课列表</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:order:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" disabled :rules="rules" label-width="125px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单标题" prop="title">
              <el-input v-model="form.title" placeholder="请输入订单标题" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单编号" prop="orderNo">
              <el-input v-model="form.orderNo" placeholder="请输入订单编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="学员姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入学员姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="家长联系方式" prop="linkPhone">
              <el-input v-model="form.linkPhone" placeholder="家长联系方式" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="实付金额" prop="totalFee">
              <el-input v-model="form.totalFee" placeholder="请输入实付金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="推荐人" prop="tjPerson">
              <el-input v-model="form.tjPerson" placeholder="请输入推荐人" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="推荐人联系方式" prop="tjPersonPhone">
              <el-input v-model="form.tjPersonPhone" placeholder="请输入推荐人联系方式" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="期望上课时间" prop="qwskDate">
              <el-input v-model="form.qwskDate" placeholder="请输入期望上课时间" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="订单时间" prop="createTime">
              <el-input v-model="form.createTime" placeholder="订单时间" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年级" prop="grade">
              <el-input v-model="form.grade" placeholder="年级" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="教材版本" prop="jcVersion">
              <el-input v-model="form.jcVersion" placeholder="教材版本" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最近考试分数" prop="ksScore">
              <el-input v-model="form.ksScore" placeholder="最近考试分数" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="订单备注" prop="remark">
          <el-input v-model="form.remark" placeholder="订单备注" :rows="5"  type="textarea" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="planclassopen" width="1300px" append-to-body>
      <plan-class :orderNo="orderNo"  v-if="planclassopen"></plan-class>
      <el-button @click="cancelclass">取 消</el-button>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="tkclassopen" width="1300px" append-to-body>
      <drop-class :orderNo="orderNo"  v-if="tkclassopen"></drop-class>
    </el-dialog>

  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, listOrderss } from '@/api/business/order'
import PlanClass from '@/components/PlanClass'

import DropClass from '@/views/course/dropClass/index.vue'
export default {
  name: "Order",
  components: { PlanClass,DropClass },
  data() {
    return {
      // 遮罩层
      loading: true,
      tkclassopen:false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      planclassopen:false,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        userId: null,
        productId: null,
        totalFee: null,
        yhJe: null,
        ylJe: null,
        orderStatus: null,
        tjPerson: null,
        tjPersonPhone: null,
        qwskDate: null,
        title: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      orderNo:""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrderss(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelclass(){
      this.planclassopen = false;
    },


    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        userId: null,
        productId: null,
        totalFee: null,
        yhJe: null,
        ylJe: null,
        orderStatus: null,
        tjPerson: null,
        tjPersonPhone: null,
        qwskDate: null,
        title: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.planclassopen=true;
      this.orderNo=row.orderNo;

    },
    handleUpdatetk(row){
      // 退课列表
      this.orderNo=row.orderNo;
      this.tkclassopen=true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
